<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Cuoti extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'cuoti';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'subject_text'
    ];
    

    
    public function getSubjectList()
    {
        return ['shengwu' => __('Shengwu'), 'zhengzhi' => __('Zhengzhi'), 'dili' => __('Dili'), 'lishi' => __('Lishi'), 'wuli' => __('Wuli'), 'huaxue' => __('Huaxue'), 'yingyu' => __('Yingyu'), 'shuxue' => __('Shuxue'), 'yuwen' => __('Yuwen')];
    }


    public function getSubjectTextAttr($value, $data)
    {
        $value = $value ?: ($data['subject'] ?? '');
        $list = $this->getSubjectList();
        return $list[$value] ?? '';
    }




    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
